import _ from 'lodash-es';

export function parseEnv(env: Record<string, any>): ViteEnv {
    const envs = _.cloneDeep(env);
    Object.entries(env).forEach(([key, value]) => {
        if (['true', 'false'].includes(value)) envs[key] = value === 'true';
        else if (/^\d+$/.test(value)) envs[key] = Number(value);
        else if (value == 'null') envs[key] = null;
        else if (value == 'undefined') envs[key] = undefined;
        else envs[key] = value;
    })
    return envs as ViteEnv;
}